/**
 * 车辆档案Api接口
 */

import { message } from "antd";
import { basicIp, newHttpService } from "../../api/http"

export type ISelectList = {
    label: string;
    value: string;
    disabled?: boolean;
};

///gb-pickup-regis/carList  获取全部车牌号 

export const getCarList = () => {
    const url = basicIp + "/gb-pickup-regis/carList"
    return newHttpService.getData(url)
}
//gb-pickup-regis/goodList 获取货品列表
export const getGoodList = () => {
    const url = basicIp + "/gb-pickup-regis/goodList"
    return newHttpService.getData(url)
}

export const handlegetGoodList = async () => {
    const { code, msg, data } = (await getGoodList()) as { code: number, msg: string, data: string[] };
    if (code === 20000) {
        let arr: ISelectList[] = [];
        data.forEach(element => {
            arr.push({
                value: element,
                label: element
            })
        });
        return arr;
    } else {
        message.error(msg);
        return [];
    }
}

//gb-pickup-regis/select 查询车辆档案
export const postSelect = (data: ISelectType) => {
    const url = basicIp + "/gb-pickup-regis/select"
    return newHttpService.postData(url, data)
}

export interface ISelectType{
    carColor?:string 
    carNum?:string
    good?:string 
    telPhone?:string 
    currentPage?:number
    pageSize?:number
}

export interface ISelectListType{
    id?:string
    carColor:string
    carNum:string
    good:string
    telPhone:string
    allowAmount:number
    remainAmount?:number
    driverName:string
    emptyWeight:number
}

//gb-pickup-regis/delete 删除车辆 
export const getPrDelete = (data: { id?: string }) => {
    const url = basicIp + "/gb-pickup-regis/delete"
    return newHttpService.getData(url, data)
}

//gb-pickup-regis/carMessage 根据车牌号获取车辆信息
export const getCarMessage = (data: { carNum: string ,carColor:string}) => {
    const url = basicIp + "/gb-pickup-regis/carMessage"
    return newHttpService.getData(url, data)
}

//gb-pickup-regis/regis 注册车辆
export const getPrRegis = (data: ISelectListType) => {
    const url = basicIp + "/gb-pickup-regis/regis"
    return newHttpService.postData(url, data)
}

//gb-pickup-regis/update 更新车辆
export const getPrUpdate = (data: ISelectListType) => {
    const url = basicIp + "/gb-pickup-regis/update"
    return newHttpService.postData(url, data)
}

//gb-pickup-regis/emptyDetail 空车重量详情
export const getEmptyDetail = (data: { id: string }) => {
    const url = basicIp + "/gb-pickup-regis/emptyDetail"
    return newHttpService.getData(url, data)
}

export interface IEmptyDetailType{
    id:string
    pickId:number 
    beforeWeight:number 
    behindWeight:number 
    reason:string
    updateRecordTime:string
}

//gb-pickup-regis/updateEmpty 更新空车重量
export const getUpdateEmpty = (data: { id: string, emptyWeight: number, reason: string }) => {
    const url = basicIp + "/gb-pickup-regis/updateEmpty"
    return newHttpService.postData(url, data)
}